package com.example.filepertest

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.filepertest.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    private  val TAG = "MainActivity"
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.button?.setOnClickListener {
            Log.d(TAG, "onCreate: ")
            val editor = getSharedPreferences("data", Context.MODE_PRIVATE).edit()
            editor.putString("name", "Tom")
            editor.putInt("age", 28)
            editor.putBoolean("married", false)
            editor.apply()
        }
        binding.button2?.setOnClickListener {
            getSharedPreferences("data", Context.MODE_PRIVATE).apply {
                val name = getString("name", "Unknown")
                val age = getInt("age", -1)
                val isMarried = getBoolean("married", false)
                Log.d(TAG, "onCreate: name = $name, age = $age, isMarried = $isMarried")

            }

        }









        enableEdgeToEdge()

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }
}